package ai.moran.demo.service.impl;

import ai.moran.demo.config.RedissonConfig;
import ai.moran.demo.service.Test;
import org.redisson.RedissonReadLock;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.logging.Logger;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ai.moran.demo.mapper.PersonTableMapper;
import ai.moran.demo.entity.PersonTable;
import ai.moran.demo.service.PersonTableService;
import org.springframework.transaction.annotation.Transactional;
import sun.rmi.runtime.Log;

/**
 * @author zhuhaitao
 * @email zhuhaitao@imoran.net
 * @date 2020/7/30 1:19 下午
 */
@Service
public class PersonTableServiceImpl extends ServiceImpl<PersonTableMapper, PersonTable> implements PersonTableService,Runnable{


    @Autowired
    private Test test;
    @Autowired
    private RedissonConfig redissonConfig;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void test1(){
        PersonTable personTable=new PersonTable();
        personTable.setName("小明");
        this.save(personTable);
        try {
            test.test2();
        }catch (Exception e){
            System.out.println("===");
        }
    }



    @Override
    public void run() {
        //1.创建锁
        RLock lock= redissonConfig.getClient().getLock(redissonConfig.OUTBOUNDJOBDETAIL_GETNEXTUNCALL);
        lock.lock();
        PersonTable personTable=this.getById(1);
        personTable.setAge(personTable.getAge()+1);
        this.updateById(personTable);
        lock.unlock();
    }
}
